import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { RechargeService } from './recharge.service';
import { CreateRechargeDto } from './dto/create-recharge.dto';
import { PageQuery } from '../../../util/entity/page.entity';
import { Recharge } from './entities/recharge.entity';
import { UpdateRechargeDto } from './dto/update-recharge.dto';
import { ReqUser } from '../../../common/decorator/user.decorator';

@Controller()
export class RechargeController {
  constructor(private readonly rechargeService: RechargeService) {}

  @Post()
  create(@Body() createRechargeDto: CreateRechargeDto) {
    return this.rechargeService.create(createRechargeDto);
  }

  @Post('buy/:id')
  buy(@Param('id') id: number, @ReqUser('id') userId: number) {
    return this.rechargeService.buy(id, userId);
  }

  @Post('list')
  findAll(@Body() pageQuery: PageQuery<Recharge>) {
    return this.rechargeService.findAll(pageQuery);
  }

  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.rechargeService.findOne(id);
  }

  @Patch(':id')
  update(
    @Param('id') id: number,
    @Body() updateRechargeDto: UpdateRechargeDto,
  ) {
    return this.rechargeService.update(id, updateRechargeDto);
  }

  @Delete(':id')
  remove(@Param('id') id: number) {
    return this.rechargeService.remove(id);
  }
}
